Imports Microsoft.VisualBasic

Public Class CLS_SQL
    Private sFields As String = "*"
    Private dFields() As String
    Private vFields() As String
    Private orderby As String
    Private between As String

    Public Function DoSelect(ByVal TableName As String)
        Dim SQL As String
        Dim i As Integer
        SQL = "SELECT " & sFields & " FROM " & TableName & " WHERE ROWID LIKE '%%' "
        For i = 0 To UBound(dFields) 
            If vFields(i) <> Nothing And vFields(i) <> "%%" Then
                If i = 0 Then
                    SQL &= " AND " & dFields(i) & " '" & vFields(i) & "'"
                Else
                    SQL &= " AND " & dFields(i) & " '" & vFields(i) & "'"
                End If
            End If
        Next
        If orderby <> Nothing Then
            SQL &= " ORDER BY " & orderby
        End If
        Return SQL
    End Function

    Public Function DoSelectInf(ByVal TableName As String)
        Dim SQL As String
        Dim i As Integer
        SQL = "SELECT " & sFields & " FROM " & TableName & " "
        For i = 0 To UBound(dFields)
            If vFields(i) <> Nothing Then
                If i = 0 Then
                    SQL &= " WHERE " & dFields(i) & " '" & vFields(i) & "'"
                Else
                    SQL &= " AND " & dFields(i) & " '" & vFields(i) & "'"
                End If
            End If
        Next
        If orderby <> Nothing Then
            SQL &= " ORDER BY " & orderby
        End If
        Return SQL
    End Function

    Public Sub DoSelectFields(ByVal Fields As String)
        Me.sFields = Fields
    End Sub

    Public Sub AddFilds(ByVal Fields As String, ByVal Values As String, ByVal Index As Integer)
        ReDim Preserve dFields(Index)
        ReDim Preserve vFields(Index)
        Me.dFields(Index) = Fields
        Me.vFields(Index) = Values
    End Sub

    Public Sub AddOrderBy(ByVal Fields As String)
        Me.orderby = Fields
    End Sub
End Class
